﻿#include "CameraVisionKit.h"

namespace Qly {

inline double scaleFromStandardRange(double min, double max, double value)
{
    return min + (value + 1.0) * (max - min) / 2.0;
}

inline double scaleToStandardRange(double min, double max, double value)
{
    return -1.0 + 2.0 *  (value - min) / (max - min);
}

bool VisionKitCameraImageProcessing::setWhiteBalanceMode(WhiteBalanceMode mode)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::whiteBalanceMode(WhiteBalanceMode &mode)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::setWhiteBalance(int red, int green, int blue)
{
    setWhiteBalanceRed(red);
    setWhiteBalanceGreen(green);
    return setWhiteBalanceBlue(blue);
}

bool VisionKitCameraImageProcessing::setWhiteBalanceRed(int red)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setWhiteBalanceGreen(int green)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::setWhiteBalanceBlue(int blue)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::whiteBalance(int &red, int &green, int &blue)
{
    int min, max;
    whiteBalanceRedRange(min, max, red);
    whiteBalanceGreenRange(min, max, green);
    return whiteBalanceBlueRange(min, max, blue);
}

bool VisionKitCameraImageProcessing::whiteBalanceBlueRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::whiteBalanceRedRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }
     return false;
}

bool VisionKitCameraImageProcessing::whiteBalanceGreenRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::autoWhiteBalance(bool &on)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::brightness(double &value)
{
    int min, max, nValue;
    if( brightnessRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setBrightness(double value)
{
    //获取相机图像的亮度信息
    return false;
}


bool VisionKitCameraImageProcessing::brightnessRange(int &min, int &max, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::gammaRange(double &min, double &max, double &fValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::gamma(double &v)
{
    double min, max;
    return gammaRange(min, max, v);
}

bool VisionKitCameraImageProcessing::setGamma(double v)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::gammaEnable(bool &on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::setGammaEnable(bool on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::gainRange(double &fMin, double &fMax, double &fValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::gain(double &fValue)
{
    double min, max;
    return gainRange(min, max, fValue);
}

bool VisionKitCameraImageProcessing::setGain(double fValue)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }


    return false;
}

bool VisionKitCameraImageProcessing::setGainMode(GainMode mode)
{
    return false;
}

bool VisionKitCameraImageProcessing::autoGain(bool &on)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::autoGainLowerLimitRange(double &fMin, double &fMax, double &fValue)
{
    return false;
}

bool VisionKitCameraImageProcessing::autoGainUpperLimitRange(double &fMin, double &fMax, double &fValue)
{
    return false;
}

bool VisionKitCameraImageProcessing::autoGainLowerLimit(double &fValue)
{
    double min, max;
    return autoGainLowerLimitRange(min, max, fValue);
}

bool VisionKitCameraImageProcessing::autoGainUpperLimit(double &fValue)
{
    double min, max;
    return autoGainUpperLimitRange(min, max, fValue);
}

bool VisionKitCameraImageProcessing::sharpnessEnable(bool &on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::setSharpnessEnable(bool on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::setSharpness(double value)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::sharpness(double &value)
{
    int min, max, nValue;
    if( sharpnessRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::sharpnessRange(int &min, int &max, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::blackLevel(double &value)
{
    int min, max, nValue;
    if( blackLevelRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setBlackLevel(double value)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::blackLevelRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::contrastRange(int &nMin, int &nMax, int &nValue)
{
    // 海康相机暂时不支持 Contrast 参数
    nMin = -1;
    nMax = 1;
    nValue = 0;
    return false;
}

bool VisionKitCameraImageProcessing::contrast(double &value)
{
    int min, max, nValue;
    if( contrastRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setContrast(double value)
{
    Q_UNUSED(value);
    return false;
}

bool VisionKitCameraImageProcessing::saturation(double &value)
{
    int min, max, nValue;
    if( saturationRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setSaturation(double value)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::saturationRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::setSaturationEnable(bool on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::saturationEnable(bool &on)
{
    if( m_hDevHandle == nullptr ) return false;

    return false;
}

bool VisionKitCameraImageProcessing::denoiseEnable(bool &on)
{
    if( m_hDevHandle == nullptr ) return false;


    return false;
}

bool VisionKitCameraImageProcessing::setDenoiseEnable(bool on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::denoise(double &value)
{
    int min, max, nValue;
    if( denoiseRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::setDenoise(double value)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::denoiseRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::hueEnable(bool &on)
{
    if( m_hDevHandle == nullptr ) return false;


    return false;
}

bool VisionKitCameraImageProcessing::setHueEnable(bool on)
{
    if( m_hDevHandle == nullptr ) return false;
    return false;
}

bool VisionKitCameraImageProcessing::setHue(double value)
{
    if(m_hDevHandle == nullptr)
    {
        return false;
    }

    return false;
}

bool VisionKitCameraImageProcessing::hue(double &value)
{
    int min, max, nValue;
    if( hueRange(min, max, nValue) )
    {
        value = scaleToStandardRange(min, max, nValue);
        return false;
    }
    return false;
}

bool VisionKitCameraImageProcessing::hueRange(int &nMin, int &nMax, int &nValue)
{
    if (NULL == m_hDevHandle)
    {
         return false;
    }

    return false;

}


} //namespace Qly
